home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 130 / gfatip15 / gfatip15.doc < prev    next >
Text File  |  1988-02-05  |  13KB  |  318 lines

  1.  
  2.  
  3.                                                 January 16, 1988
  4.  
  5.  
  6.                            GFATIP15.DOC
  7.  
  8.                                 by
  9.  
  10.                        Barbara J. Behuniak
  11.                    Principle Systems Programmer
  12.                            & President
  13.                      Marathon Computer Press
  14.                                 & 
  15.                          John B. Holder
  16.                      Senior Software Engineer
  17.                      Marathon Computer Press
  18.            Asst. Sysop on GEnie's MichTron Roundtable
  19.                                 & 
  20.                             Brian Lake
  21.           Associate Programmer, Marathon Computer Press
  22.  
  23.      This is the 15th in a planned series of GFA Tip files.  The 
  24. topic of this issue is building a software reset routine for GFA 
  25. Basic.  In this archive you will find the following files:
  26.  
  27.                             Reboot2.S
  28.                             Reboot2.O
  29.                            GFATIP15.DOC
  30.                            GFATIP15.LST
  31.                            GFABOOT.PRG
  32.  
  33.  
  34. Background:
  35.  
  36.      The idea for this series of utility procedures came about out 
  37. of a need for a software driven reset.  By this we mean that we 
  38. needed to be able to reset the computer just as if the user had 
  39. pressed the reset button on the back of their computer.  
  40.      Occasionally a programmer, {predominantly systems level} will 
  41. need to accomplish this as a convenience to the user or to abort 
  42. an otherwise corrupted system.
  43.  
  44. Why For GFA Basic?:
  45.  
  46.      There is really no reason why GFA Basic programmers have to 
  47. feel that some things simply can't be done with GFA Basic.  It is 
  48. a common misconception that some languages are all things to all 
  49. people if they can master them.  Many Basic programmers think that 
  50. systems level programming must be left to those spooky people that 
  51. have little dark rooms in their basement with a supermicro.  The 
  52. same starting Basic programmer often gets this picture of a 
  53. man/woman like this and will either quit or become discouraged 
  54. when confronted with an otherwise insurmountable problem.  So a 
  55. small portion feel that they must then abandon Basic and venture 
  56. out in search of knowledge to overcome the Basic Doldrums.  I 
  57. personally wonder just how many of these would be {explorers} are 
  58. lost in the sea of confusion.  There is absolutely no reason for 
  59. this to happen.  What we are proposing is that the programmer need 
  60. not beseech his language, but augment it with another language 
  61. from time to time.  Very few programs can be roughed out with the 
  62. ease and facility of Basic, and even fewer with a Basic slighter 
  63. than GFA Basic.  Since we have such a fast and able version of 
  64. Basic, let's use it.  If per chance you ever find routines that 
  65. are just not fast enough or are not really suited for the embedded 
  66. command suite of GFA Basic, our mentor {Frank Ostrowski, Creator 
  67. of GFA Basic}, has added the ability to use modules created with 
  68. another language such as C with the "C:" command or perhaps 
  69. Assembled programs with the "Call" command.  By doing so we have a 
  70. wonderful (modern) language that allows for the programmer to drop 
  71. down a notch or two to conduct some things not really possible 
  72. with the parent language.  I think the hooks left by the developer 
  73. were very thoughtful indeed and have made the GFA Basic language a 
  74. favorite among Hackers and Commercial Developers alike.
  75.  
  76.      Well, I suppose we have been on our soapbox long enough so we 
  77. should really get started with the documentation for this GFATIP.
  78.  
  79. GFA Basic and Assembler:
  80.  
  81.      For this GFATIP we will be utilizing a subroutine written in 
  82. MC68000 Assembler, (The language that GFA Basic itself is written 
  83. in).  The purpose is to show you how to utilize a routine such as 
  84. this, and to give you access to a powerful extension to the GFA 
  85. Basic language.  It's really short in description so let's get 
  86. started.
  87.  
  88. The Problem:
  89.  
  90.      We needed a routine to emulate the press of the reset button, 
  91. but without the user physically doing so.
  92.  
  93. The Assembler Solution To Our Problem:
  94.  
  95.  
  96. gfaboot:         clr.l   0x420           
  97.  
  98.      In the above line we have a label, (gfaboot), and a 
  99. instruction in MC68000 language followed by an attribute.  Clr 
  100. means "Clear an Operand", and the .l means long.  It can also be 
  101. either byte or word.  The actual location that we happen to be 
  102. clearing is 0x420 {memvalid}, or in GFA Basic (&H420).  This is 
  103. the system location that checks to see of the memory controller's 
  104. configuration is valid.
  105.  
  106.                  clr.l   0x43a           
  107.  
  108.      In the next location is the second half {memval2}.
  109.  
  110.                  movea.l 0, a7          
  111.  
  112.      Now we move on to a new MC68000 instruction with a new 
  113. purpose.  We will use movea which is designed to move the content 
  114. of the source to the destination address register.  The size of 
  115. the operation may be specified to be of word on long size in 
  116. length.  Word size source operands are going to be sign extended 
  117. to full 32 bit lengths in advance of completion.  In this instance 
  118. we are grabbing the system startup stack.
  119.  
  120.                  movea.l 4, a0           
  121.  
  122.      By using the same MC68000 instruction we will accomplish the 
  123. grab of the system startup program counter.
  124.  
  125.                  jmp     (a0)            
  126.  
  127.      In the next instruction we conduct a jump to the startup 
  128. routine or {reboot}.  The jmp MC68000 simply moves you to the 
  129. specified effective address {A0} that's specified by the 
  130. instruction.  And wala! A software Reset is in the making!  Since 
  131. we never return this is the last hurrah for our routine and the 
  132. calling program.
  133.  
  134. {Attribute Conventions:}
  135.  
  136.      Above you see instructions followed by a "." and then a 
  137. single letter.  These mean the following:
  138.  
  139.           .b  = Byte, 8 bits
  140.           .w  = Word, 16 bits, double byte
  141.           .l  = Long, 32 bits, double word
  142.  
  143.  
  144. The finished ASM source:
  145.  
  146. gfaboot:         clr.l   0x420           
  147.                  clr.l   0x43a         
  148.                  movea.l 0, a7           
  149.                  movea.l 4, a0           
  150.                  jmp     (a0)           
  151.  
  152.  
  153.      Pretty simple huh?  Well maybe not all that simple, but 
  154. pretty darned effective to kick your old ST in the seat of the 
  155. pants!  Now before we progress any further, let's answer a few 
  156. questions about how to get this into something that GFA Basic can 
  157. use.
  158.  
  159.      For this sample ASM routine we used Mark Williams C and the 
  160. 'AS' command {it's simple assembler}.  You should be able to use 
  161. any of the other assemblers on the market also, ie.. GenSt 
  162. (HiSoft), AssemPro (Abacus), or the MetaComCo 68000 Assembler.  
  163. Once our source file was created, we issued the following command 
  164. while under the control of MSH { The command line interpreter }:
  165.  
  166.                         cc -A -c reboot.s
  167.  
  168. Nota Bene: { The -A option tells the Mark Williams C compiler that 
  169. if there are any errors, please send us back to the editor (Micro 
  170. EMACS), and show us where we failed.  Nice for detecting errors 
  171. and saving valuable time with larger programs than this.}
  172.  
  173.  
  174.      By doing so we told the C compiler driver to supress the 
  175. linking and removal of the .O object file created during assembly.  
  176. All we wanted was the raw assembled file.
  177.  
  178.      After that was accomplished, we tackled the creation of the 
  179. GFA Basic compatible program incorporation of the object file with 
  180. the help of the GFA Basic Book {by Frank Ostrowski of GFA 
  181. Systemtechnik}.  A short utility contained in the GFA Basic book 
  182. helped us to turn the object file into the nitty gritty 
  183. unrelocated MC68000 assembled data that we desired.  << By the 
  184. way, The GFA Basic Book is a MUST for any of you that desire to 
  185. learn how to interface Machine Language with GFA Basic. >>  Once 
  186. we had the data statements it was just a matter of putting the 
  187. program together.
  188.  
  189.      First step was to allocate a variable to hold the ASM data.  
  190. This we called Reboot$.  Next we used a subroutine call to load 
  191. the ASM data in the variable, thus Insert_rebooter_asm was born.  
  192. Then we made a call to the Xbios 38 function Supexec (Made 
  193. infinitely easier by The GFA Basic Companion II source code 
  194. libraries {Provided here by express permission of Marathon 
  195. Computer Press and MichTron Inc.})  The reason why we must use the 
  196. Supexec call is that all calling procedures trying to access 
  197. memory locations between &H0 and &H800 have to move into a 
  198. 'Supervisor Mode' of operation.
  199.      Although dangerous in the developmental stages, it's 
  200. imperative to do so in the finished product.  This call is not for 
  201. the 'just starting beginner' or weak of heart and even those that 
  202. do not follow the 11th commandment "Thou shalt not be caught dead 
  203. without current backups!"
  204.      
  205.  
  206. The GFA Basic Source:
  207.  
  208. '                             GFATIP15.BAS
  209. '                Copyright 1988 Marathon Computer Press
  210. '                              Written by
  211. '                           Barbara J. Behuniak
  212. '                             John B. Holder
  213. '                                Brian Lake
  214. '
  215. '  This tip file and the rest of the archive are in the public domain in so
  216. ' far as no charge of any kind is assessed for the distribution of it in it's
  217. ' entirety.  Marathon Computer Press retains all rights the code contained
  218. ' herein.  You may use any or all of the code in any application you write for
  219. ' commercial or non-commercial use.  Please give us credit if you do so.
  220. '
  221. '
  222. '
  223. ' Now let's call our procedures to make the end result of a software reboot.
  224. '
  225. '
  226. @Do_a_reboot ! Call in the ST Wreckers..
  227. ' Once called your system will reboot just as if you pressed the reset.
  228. '
  229. '
  230. Procedure Do_a_reboot
  231.   Reboot$=""
  232.   @Insert_rebooter_asm
  233.   Machine_code%=Varptr(Reboot$)
  234.   @Supexec(Machine_code%)
  235.   '
  236. Return ! Even though we never will.
  237. '
  238. '
  239. '
  240. Procedure Insert_rebooter_asm
  241.   '
  242.   Do
  243.     Read Asm%
  244.     Exit If Asm%<0
  245.     Reboot$=Reboot$+Mki$(Asm%)
  246.   Loop
  247.   '
  248. Return
  249. '
  250. '
  251. '
  252. ' Disassembled Machine code for the file REBOOT2.O
  253. '
  254. Data 0,0,0,0,0,5632,0,0
  255. Data 0,0,17081,0,1056,17081,0,1082
  256. Data 11897,0,0,8313,0,4,20176,26470
  257. Data 24930,28527,29696,0,0,0
  258. Data -1
  259. '
  260. '
  261. ' This next Xbios routine is not for Beginners!!!!!!!
  262. ' It will execute a routine in the 68000 supervisor mode
  263. ' The address must be passed in this manner:
  264. ' Prog_address=Varptr("function")
  265. ' For example you Bload a ML program in the variable Prog$, then you would
  266. ' use Prog_address=Varptr(Prog$)
  267. '
  268. '
  269. ' This routine was extracted from the GFA Basic Companion II .LST library and
  270. ' is Copyright 1988 Marathon Computer Press.  Provided in this GFATIP by
  271. ' MichTron and Marathon Computer Press as a public service.
  272. '
  273. Procedure Supexec(Machine_code%)
  274.   Dummy=Xbios(38,L:Machine_code%)
  275. Return
  276.  
  277.  
  278. Closing Remarks:
  279.  
  280.      Please don't be one of those 'would be' Basic programmers 
  281. that decided playing games is really better than programming 
  282. anyways..  Don't get frustrated, get even... with all those C, 
  283. Pascal, and Modula 2 programmers that say that Basic is dead and 
  284. can't be used for serious programming projects.  And most of all 
  285. support GFA Basic & it's development tools.  As a last thought, 
  286. please consider the programmers and support staff of any 
  287. commercially produced software product the next time someone 
  288. offers you a "free" copy of a Copyrighted Software Program.  By 
  289. becoming one of the growing ranks of software "PIRATES", you would 
  290. only be joining the ranks of the #1 public enemy of Microcomputer 
  291. users.  Let's join together and protect the goose that laid the 
  292. golden egg.  You may write to the below organization to make a 
  293. statement in support of this cause.
  294.  
  295.                               CHART
  296.          (Computer Hobbyists Against Raiders And Thieves)
  297.                           P.O. Box 97276
  298.                       Pittsburgh, PA  15229
  299.  
  300.  
  301.  
  302.                      Comments and PD release
  303.  
  304.      This GFATIP file is in the public Domain.  However, the 
  305. documentation file and source is Copyright 1988 by Marathon 
  306. Computer Press, and is provided as a public service.  You may not 
  307. include the text of this file in any publication, or newsletter 
  308. without the approval of Marathon Computer Press.  The source code 
  309. and idea are Copyright 1988 by Marathon Computer Press also, but 
  310. you may use it as you see fit if you give us a mention of credit 
  311. in your program code {if provided in source} or documentation.  
  312. You may also post this file on any bulletin board as long as it is 
  313. posted in it's entirety.  Absolutely NO charge (of any kind) may 
  314. be assessed for providing this Tip to the public.  If it's not 
  315. 100% Free, don't do it!  Nuff Said.
  316.  
  317.  
  318.